﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FileManager
{
    public partial class Form1 : Form
    {
        Model m_Model = new Model();

        public Form1()
        {
            InitializeComponent();
            m_Model.setDrive("C:", true);
            m_Model.setDrive("C:", false);
            comboBox1.SelectedText = "C:";
            comboBox2.SelectedText = "C:";
            Startup();
        }

        private void Del_Click(object sender, EventArgs e)
        {
            if (listBox1.Focused)
            {
                m_Model.deleteFile(listBox1.SelectedIndex, false);
            }
            else if (listBox2.Focused)
            {
                m_Model.deleteFile(listBox2.SelectedIndex, true);
            }
        }

        public void Startup()
        {
            comboBox1.Items.Clear();
            comboBox2.Items.Clear();

            foreach (string str in m_Model.getDriveList())
            {
                comboBox1.Items.Add(str);
                comboBox2.Items.Add(str);
            }

            listBox1.Items.Clear();
            listBox2.Items.Clear();
            foreach (FileInfo fi in m_Model.getFileList(false))
            {
                listBox1.Items.Add(fi.Name);
            }

            foreach (FileInfo fi in m_Model.getFileList(true))
            {
                listBox2.Items.Add(fi.Name);
            }
        }

       
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
                m_Model.itemDblClick(listBox1.SelectedIndex, false);
        }

        private void Copy_Click(object sender, EventArgs e)
        {
            if (listBox1.Focused)
            { 
                m_Model.copyFile(listBox1.SelectedIndex, false); 
            }
            else if (listBox2.Focused)
            {
                m_Model.copyFile(listBox2.SelectedIndex, true);
            }
           

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_Model.setDrive(Convert.ToString(comboBox1.SelectedItem), false);
            Startup();
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_Model.setDrive(Convert.ToString(comboBox2.SelectedItem), true);
            Startup();
        }

        private void listBox2_DoubleClick(object sender, EventArgs e)
        {
            m_Model.itemDblClick(listBox2.SelectedIndex, true);
        }
    }
}
